//
//  HBIndexCtrl.m
//  HuoBao
//
//  Created by sky on 15/11/26.
//  Copyright © 2015年 jinxin. All rights reserved.
//

#import "HBIndexCtrl.h"
#import "HBLoginCtrl.h"
#import "HBRegisterCtrl.h"
#import "HBTabBarViewController.h"

#define GetFinalResult(x,y,z,r) (IsIphone4?x:(IsIphone6P?r:(IsIphone5?y:z)))

#define TOTOP          GetFinalResult(120,160,450/2,450/2)
#define TOPTOLOGO     GetFinalResult(50,90,251/2,251/2)
#define TOPTORIS     GetFinalResult(158/2 - 10,158/2 - 5,158/2,158/2)


@interface HBIndexCtrl ()

@end

@implementation HBIndexCtrl

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:YES];
    [self.navigationController setNavigationBarHidden:YES animated:animated];
//    if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
//        self.navigationController.interactivePopGestureRecognizer.enabled = YES;
//    }
}

-(void)buildLayout{
    UIImage *bgimage = [UIImage imageNamed:@"login_bg"];
    UIImageView *bgview = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    bgview.image = bgimage;
    [self.view addSubview:bgview];
    
    UIImage *logo = [UIImage imageNamed:@"login_logo"];
    UIImageView *logovi = [[UIImageView alloc]initWithFrame:CGRectMake(SCREEN_WIDTH/2 - logo.size.width/2, TOTOP, logo.size.width, logo.size.height)];
    logovi.image = logo;
    [self.view addSubview:logovi];
    
    UILabel *sologin = [self LabelWithRect:CGRectMake(0, logovi.origin.y + logo.size.height + 11, SCREEN_WIDTH, 12) textColor:[LCCommon getColor:@"a8a8a8"] textstr:@"丰富你的生活,丰富你的钱包!" textfont:12 textstyle:NSTextAlignmentCenter];
    [self.view addSubview:sologin];
    
    UIButton *loginbtn = [[UIButton alloc]initWithFrame:CGRectMake(40, sologin.origin.y + 12 + TOPTOLOGO, SCREEN_WIDTH - 80, 45)];
    loginbtn.backgroundColor = [LCCommon getColor:@"d9d9d9"];
    [loginbtn setTitle:@"登录" forState:UIControlStateNormal];
    [loginbtn setBackgroundColor:[LCCommon getColor:@"656565"] forState:UIControlStateHighlighted];
    loginbtn.titleLabel.font = [UIFont systemFontOfSize:18];
    [loginbtn setTitleColor:[LCCommon getColor:@"070708"] forState:UIControlStateNormal];
    loginbtn.clipsToBounds = YES;
    loginbtn.layer.cornerRadius = 4;
    [loginbtn addTarget:self action:@selector(btntologin) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:loginbtn];
    
    
    UIButton *regisbtn = [[UIButton alloc]initWithFrame:CGRectMake(40, loginbtn.origin.y + 45 + 46/2, SCREEN_WIDTH - 80, 45)];
    regisbtn.backgroundColor = [LCCommon getColor:@"d9d9d9"];
    [regisbtn setTitle:@"注册" forState:UIControlStateNormal];
    [regisbtn setBackgroundColor:[LCCommon getColor:@"656565"] forState:UIControlStateHighlighted];
    regisbtn.titleLabel.font = [UIFont systemFontOfSize:18];
    [regisbtn setTitleColor:[LCCommon getColor:@"070708"] forState:UIControlStateNormal];
    regisbtn.clipsToBounds = YES;
    regisbtn.layer.cornerRadius = 4;
    [regisbtn addTarget:self action:@selector(btntoregis) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:regisbtn];
    
    
    UIImage *guang = [UIImage imageNamed:@"login_guang"];
    UIImageView *ggview = [[UIImageView alloc]initWithFrame:CGRectMake(SCREEN_WIDTH - guang.size.width - 68/2, regisbtn.origin.y + 45 + TOPTORIS, guang.size.width, guang.size.height)];
    //ggview.userInteractionEnabled = YES;
    ggview.image = guang;
    //UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(taptoGu)];
    //[ggview addGestureRecognizer:tap];
    [self.view addSubview:ggview];
    
    UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(ggview.origin.x - 15, ggview.origin.y - 15, ggview.size.width + 30, ggview.size.width + 30)];
    [btn addTarget:self action:@selector(taptoGu) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn];
}


-(void)btntoregis{
    LLog(@"btntoregis");
    HBRegisterCtrl *login = [[HBRegisterCtrl alloc]initWithNibName:NSStringFromClass([HBRegisterCtrl class]) bundle:nil];
    login.nav = self.navigationController;
    login.viewJumping = isFromLoginPage;
    [self.navigationController pushViewController:login animated:YES];
}

-(void)btntologin{
    LLog(@"btntologin");
    HBLoginCtrl *login = [[HBLoginCtrl alloc]init];
    [self.navigationController pushViewController:login animated:YES];
}

-(void)taptoGu{
    LLog(@"taptoGu");
    HBTabBarViewController *tab = [[HBTabBarViewController alloc]init];
    [UIApplication sharedApplication].keyWindow.rootViewController = tab;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


-(UILabel *)LabelWithRect:(CGRect)rect textColor:(UIColor *)color textstr:(NSString *)str textfont:(int)font textstyle:(NSTextAlignment)aligment{
    UILabel *label = [[UILabel alloc] initWithFrame:rect];
    label.textColor = color;
    label.text = str;
    label.font = [UIFont systemFontOfSize:font];
    label.textAlignment = aligment;
    label.numberOfLines = 0;
    return label;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
